package com.stone.business.lsap.service;

/**
 * <pre>
 * ---临时工作安排---Service
 * </pre>
 */

import java.util.List;

import com.stone.business.lsap.pojo.TLsap;
import com.stone.business.lsap.pojo.TLsapBz;
import com.stone.utils.StringUtils;

import frm.ssh.service.BaseService;


public class LsapService extends BaseService{
	/**
	 * ....临时工作安排....
	 */
	public String doSave(TLsap entity, List<TLsapBz> list,String hiddenids) {

		String strbz = "";
		
		if (entity.getId() == 0) {

			super.save(entity);
			
			for (TLsapBz bz : list) {
				
				if (!"".equals(bz.getFzrname())) {
					bz.setDelflag("0");
					strbz = bz.getBzname() + ",";
				} else {
					bz.setDelflag("1");
				}
				bz.setLsapid(entity.getId());
				super.save(bz);
			}
			super.updateByDHql("bzname = ?", "id='" + entity.getId() + "'", new Object[]{strbz}, null, TLsap.class.getName());
			
		}else{
			super.update(entity);
			
			for (TLsapBz bz : list) {
				if (!"".equals(bz.getFzrname())) {
					bz.setDelflag("0");
					strbz = bz.getBzname() + ",";
				} else {
					bz.setDelflag("1");
				}
				super.update(bz);
			}
			
			super.updateByDHql("bzname = ?", "id='" + entity.getId() + "'", new Object[]{strbz}, null, TLsap.class.getName());
		}
		
		// 审核通过
		if (!StringUtils.isNullOrBlank(hiddenids)) {
			if (hiddenids.startsWith(",")) {
				hiddenids = hiddenids.substring(1, hiddenids.length());
			}
			if (hiddenids.endsWith(",")) {
				hiddenids =hiddenids.substring(0, hiddenids.length()-1);
			}
			super.updateByDHql("status = '9'", "id in (" + hiddenids + ")", null, null, TLsap.class.getName());
			return "审核通过。";
		}
		
		return "保存成功。";
	}
	
	/**
	 * ....提交计划....
	 */
	public String doSubmit(TLsap entity,String status) {
		
		entity.setStatus(status);
		super.update(entity);
		return "提交成功。";
	}

}
